#ifndef _FLASH_H_
#define _FLASH_H_

#define FLASH_START_ADDRESS		0x08000000

#define ERR_SIZE_OVERFLOW		1
#define ERR_PACKET_LOST  		2
#define ERR_VERIFY_FAIL			3
#define ERR_WR_PROTECTED		4
#define ERR_WR_PROT_DISABLE_FAIL     5
#define ERR_ERASE_FAIL			6
#define ERR_ADDR_OVERFLOW	7
#define ERR_WRITE_FAIL		8

typedef struct FlashAreaTag{
	uint32_t Address;
	uint32_t Size;
}FlashArea_T;

void Flash_Init(void) ;
uint32_t Flash_Size(void);
FlashArea_T * Flash_GetAppArea(void);
FlashArea_T *Flash_GetFlashArea(void);
uint32_t Flash_UnProtect(uint32_t Start_Address, uint32_t Size);
uint32_t Flash_ErasePages(uint32_t Start_Address, uint32_t Total);
uint32_t Flash_WirteData(uint32_t Address, uint8_t Data[], uint32_t Len);
void Flash_WriteAppCompeletFlag(uint32_t Flag);
uint32_t Flash_ReadAppCompeletFlag(void);
uint32_t Flash_EraseAppArea(void);

void Flash_Read32Buf(uint32_t address, uint32_t buf[], uint32_t len);

uint32_t Flash_Write32Buf(uint32_t address, uint32_t buf[], uint32_t len);

uint32_t Flash_SyncAppCompeletFlag(void);

void Flash_FlagInit(void);
uint32_t Flash_ReadFlag(uint32_t number);
uint32_t Flash_ModifyFlag(uint32_t number, uint32_t flag);
uint32_t Flash_UpdateFlag(void);

void Flash_Cach(uint32_t pageAddress);
int Flash_Sync(void);

#endif




































